


ALTER   proc sp_update_lot_cost
@process_step_id bigint,
@location_id int,
@lot_number varchar(20),
@lot_quantity int,
@lot_id bigint
AS

declare @temp_lot_id bigint
declare @previous_process_step_id bigint
declare @temp_cost float
declare @temp_actual_cost float
declare @normal_cost float

set @normal_cost = 0.0

select @previous_process_step_id = (select ProcessStep_ID from Process_Step_Traverse_Table where Next_ProcessStep_ID = @process_step_id)

select @temp_lot_id =Lot_ID, @temp_cost = Lot_Cost from Lot_Table where ProcessStep_ID = @previous_process_step_id and Lot_Number= @lot_number

set @normal_cost = (select PSLT_Cost_Normal from Process_Step_Location_Table where ProcessStep_ID = @process_step_id and Location_ID = @location_id)
print 'NORMAL COST = '
print  @normal_cost
if @normal_cost is not null
begin
	print 'This is check'
	if @temp_cost is null
	begin
		set @temp_cost = 0
	end
	set @temp_actual_cost =  ((@normal_cost * @lot_quantity)+ @temp_cost)
end
else
begin
	if @temp_cost is null
	begin
		set @temp_cost = 0
	end
	set @temp_actual_cost =  @temp_cost
end

print 'ACTUAL COST = '
print @temp_actual_cost 
update Lot_Table set Lot_Cost=@temp_actual_cost  where Lot_ID = @lot_id




